package no.la58.scribbles.client.event;

import no.la58.scribbles.shared.LoggedInResponse;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

public class LoggedInEvent extends GwtEvent<LoggedInEvent.LoginHandler> {

    public interface LoginHandler extends EventHandler {
	public void onLoginResult(LoggedInResponse response);
    }

    public static final Type<LoginHandler> TYPE = new Type<LoginHandler>();
    private LoggedInResponse response;

    public LoggedInEvent() {

    }

    public LoggedInEvent(LoggedInResponse response) {
	this.response = response;
    }

    @Override
    protected void dispatch(LoginHandler handler) {
	handler.onLoginResult(response);
    }

    @Override
    public Type<LoginHandler> getAssociatedType() {
	return TYPE;
    }

    public void setResponse(LoggedInResponse response) {
	this.response = response;
    }

    public LoggedInResponse getResponse() {
	return response;
    }

    public static void register(EventBus bus, LoginHandler handler) {
	bus.addHandler(TYPE, handler);
    }

}
